import 'dart:convert';

import 'package:flutter/cupertino.dart';
import 'package:geomancy/models/common_model.dart';
import 'package:geomancy/models/vip_price_list_model.dart';
import 'package:geomancy/tools/http.dart';

class PayAPI {
  ///获取会员套餐
  static Future<List<VipPriceItemModel>> getVipPriceList(BuildContext context) async {
    try {
      final data = await Fetch.request(Method.POST, '/pay/payConfig', context: context);
      print('data==$data');
      final result = VipPriceListModel.fromJson(json.decode(data.data));
      if (result.code == 200) {
        return result.data ?? [];
      }
      return [];
    } catch(e) {
      return [];
    }
  }
  ///获取支付宝order
  static Future<String?> getAliPayOrder(BuildContext context, {required int totalAmount, required String subject}) async {
    try {
      final data = await Fetch.request(Method.POST, '/pay/aliPay?totalAmount=$totalAmount&subject=$subject', context: context);
      final result = CommonModel.fromJson(json.decode(data.data));
      if (result.code == 200) {
        return result.data;
      }
      return null;
    } catch(e) {
      return null;
    }
  }
}